<template>
    <eui-page-frame :topHeight="150" withOutBorder="true">
        <template #top>
            <view class="content-img">
                <eui-navbar ref="EuiNavBar" :title="title" color="#000000" backgroundColor="#FFFFFF" displayable="true">
                </eui-navbar>
            </view>
        </template>
        <eui-page-content>
            <view class="footer-view">
                <eui-card title="基本信息" showTitleLine="true" top-margin="0" h-padding="20" type="upDownSingle">
                    <template #content>
                        <view class="m-list-top">
                            <eui-text v-model="mainData.c_store_id"
                                :name="getRelatedName('rdsStores', mainData.c_store_id)" type="titlename" title="目的机构"
                                occupy />
                            <eui-text v-model="mainData.c_provider"
                                :name="getRelatedName('rdsProviders', mainData.c_provider)" type="titlename" title="供应商"
                                occupy />
                            <eui-text v-model="mainData.c_sku_order" type="price" title="品种数(含赠品)" />
                            <eui-text v-model="mainData.c_n_order" type="price" title="总数量(含赠品)" />
                            <eui-text v-model="mainData.c_mk_userno"
                                :name="getRelatedName('rdsUsers', mainData.c_mk_userno)" type="titlename" title="录入" />
                            <eui-text v-model="mainData.c_mk_dt" type="rdstime" />
                            <eui-text v-model="mainData.c_au_userno" type="titlename" title="审核"
                                :name="getRelatedName('rdsUsers', mainData.c_au_userno)"
                                v-if="mainData.c_status === '3'" />
                            <eui-text v-model="mainData.c_au_dt" type="rdstime" v-if="mainData.c_status === '3'" />
                        </view>
                    </template>
                </eui-card>
                <view class="paging-view">
                    <eui-paging ref="paging" v-model="detailData" :fixed="false" :refresher-enabled="false"
                        :default-page-size="5" :loading-more-enabled="true" :show-loading-more-when-reload="true">
                        <view v-for="(item, index) in detailData" class="m-list-top">
                            <eui-text v-model="item.c_gcode" type="titlename" :name='item.c_gname'
                                :title="index + 1 + '. ' + '商品'" occupy />
                            <eui-text v-model="item.c_barcode" type="name" title="条码" />
                            <eui-text :v-model="item.c_order_pack + '/' + item.c_order_unit" type="name"
                                title="包装/单位" />
                            <eui-text v-model="item.c_n" type="price" title="订货数量" />
                            <eui-text v-model="item.c_n_free" type="price" title="订货赠品数" />
                            <eui-text v-if="sysConfig.inputType === '1'" v-model="item.c_n_pack" type="price" title="订货件数" />
                            <eui-text v-if="sysConfig.inputType === '1'" v-model="item.c_n_odd" type="price" title="订货零数" />
                            <eui-text v-if="sysConfig.inputType === '2'" v-model="item.c_n_input" type="price" title="包装数" :precision="3"/>
                            <eui-text v-model="item.c_n_rec" type="price" title="收货数量" />
                            <eui-text v-model="item.c_n_free_rec" type="price" title="收货赠品数" />
                        </view>
                    </eui-paging>
                </view>
            </view>
        </eui-page-content>
        <!-- <view class="footer-view">
            <eui-card title="基本信息" showTitleLine="true" top-margin="0" h-padding="20" type="upDownSingle">
                <template #content>
                    <view class="m-list-top">
                        <eui-text v-model="mainData.c_store_id" :name="getRelatedName('rdsStores', mainData.c_store_id)"
                            type="titlename" title="目的机构" occupy />
                        <eui-text v-model="mainData.c_provider"
                            :name="getRelatedName('rdsProviders', mainData.c_provider)" type="titlename" title="供应商"
                            occupy />
                        <eui-text v-model="mainData.c_sku_order" type="price" title="品种数(含赠品)" />
                        <eui-text v-model="mainData.c_n_order" type="price" title="总数量(含赠品)" />
                        <eui-text v-model="mainData.c_mk_userno"
                            :name="getRelatedName('rdsUsers', mainData.c_mk_userno)" type="titlename" title="录入" />
                        <eui-text v-model="mainData.c_mk_dt" type="rdstime" />
                        <eui-text v-model="mainData.c_au_userno" type="titlename" title="审核"
                            :name="getRelatedName('rdsUsers', mainData.c_au_userno)" v-if="mainData.c_status === '3'" />
                        <eui-text v-model="mainData.c_au_dt" type="rdstime" v-if="mainData.c_status === '3'" />
                    </view>
                </template>
            </eui-card>
            <view class="paging-view">
                <eui-paging ref="paging" v-model="detailData" :fixed="false" :refresher-enabled="false"
                    :default-page-size="5" :loading-more-enabled="true" :show-loading-more-when-reload="true">
                    <view v-for="(item, index) in detailData" class="m-list-top">
                        <eui-text v-model="item.c_gcode" type="titlename" :name='item.c_gname'
                            :title="index + 1 + '. ' + '商品'" occupy />
                        <eui-text v-model="item.c_barcode" type="name" title="条码" />
                        <eui-text :v-model="item.c_order_pack + '/' + item.c_order_unit" type="name" title="包装/单位" />
                        <eui-text v-model="item.c_n" type="price" title="订货数量" />
                        <eui-text v-model="item.c_n_free" type="price" title="订货赠品数" />
                        <eui-text v-model="item.c_n_pack" type="price" title="订货件数" />
                        <eui-text v-model="item.c_n_rec" type="price" title="收货数量" />
                        <eui-text v-model="item.c_n_free_rec" type="price" title="收货赠品数" />
                        <eui-text v-model="item.c_n_odd" type="price" title="订货零数" />
                    </view>
                </eui-paging>
            </view>
        </view> -->
    </eui-page-frame>
</template>

<script setup type="ts">
import { ref, reactive, onMounted } from 'vue';
import service from "@/common/service";
import { getRelatedName, getDictSelectList } from '../components/RelatedName.js';
import { getRdsUrl, rdsRequest } from '@/hooks/rdsServices';
import { mapState, mapMutations } from 'vuex'
import { useMainStore } from "@/store/modules/store";
import { useLoginStore } from "@/store/modules/useLoginStore";
import { onLoad } from "@dcloudio/uni-app";
import {getRdsSysConfig} from "@/hooks/init";

const rdsUrl = getRdsUrl();
const mainStore = useMainStore();
const loginStore = useLoginStore();
const title = ref('订单详情');
const mainData = ref({});
const detailData = ref([]);
const paging = ref(null);
const sysConfig = ref({
    inputType: '1' // 1-件数零数分别录入方式 2-自动识别含量单值录入方式
})

onLoad(async (option) => {
    await getSysConfig();
    if (option.c_po_id || option.c_po_id === 'undefined') {
        console.log("option", option)
        title.value = option.c_po_id + '详情';
        service.enjoyShowLoading('正在加载...');
        await billQuery(option.c_po_id);
        service.enjoyHideLoading();
    }
});
const getSysConfig = async () => {
  sysConfig.value.inputType = await getRdsSysConfig("供应链管理参数", "商品件数零数录入方式") || '1';
}
// 获取单据详情信息
const billQuery = async (billId) => {
    const req = {
        BillId: billId,
    };
    const result = await rdsRequest(rdsUrl.scApi, '商品订货单', 'EnjoyBillQuery', req, '521');
    if (result.ds.length > 0) {
        mainData.value = result.ds[0];
        // detailData.value = result.ds1;
        paging.value.setLocalPaging(result.ds1);
    } else {
        paging.value.setLocalPaging([]);
    }
};
const onClickGdsInfo = async (item) => {
    if (mainData.value.c_status === '3') {
        await uni.navigateTo({
            url: './orderRec?storeId=' + mainData.value.c_store_id + '&c_gcode=' + item.c_gcode + "&c_id=" + mainData.value.c_id
        });
    }
};
</script>

<style lang="scss" scoped>
@import '@/static/font/enjoyicon/iconfont.css';
@import "@/main.scss";
::v-deep .white-main {
  margin: 20rpx 0;
}
.content-img {
    background-color: #FFFFFF;
    background-size: 100% 176rpx;
    background-repeat: no-repeat;
    width: 100%;
}

.footer-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.paging-view {
    display: flex;
    flex: 1;
    flex-direction: column;
    background: $uni-bg-color-inverse;
    border-radius: 20rpx;
    margin: 10rpx 20rpx;
    padding: 20rpx;
}


// .m-main-top {
//     display: grid;
//     grid-template-columns: 51% 49%;
//     font-size: 24rpx;
// }


.m-list-top {
    display: grid;
    grid-template-columns: 51% 49%;
    // border-bottom: 1px solid $uni-border-color;
    padding: 20rpx 0;
    font-size: 24rpx;
}
</style>
